package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.DataStatus;

public class OrderSearchDialogFragment extends DialogFragment {
  protected static final String EXTRA_VALUE = "com.isunland.palmstudysystem.ui.extra_value";
  private int[] choiceIds = new int[] {
      R.string.draft, R.string.checking, R.string.hasAudited, R.string.stopup, R.string.already_out,
      R.string.all
  };
  private String[] choiceStrings = new String[choiceIds.length];
  private String dataStatus = "";
  private String dataStatusName = "";

  @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getChoiceName(), 0,
        new OnClickListener() {

          @Override public void onClick(DialogInterface arg0, int arg1) {
            //点击dialog后跳转

            switch (arg1) {
              case 0:
                dataStatus = DataStatus.NEW;
                break;
              case 1:
                dataStatus = DataStatus.WAIT_CHECK;
                break;

              case 2:
                dataStatus = DataStatus.CHECK_PASS;
                break;

              case 3:
                dataStatus = DataStatus.ABORT;
                break;

              case 4:
                dataStatus = DataStatus.OUTSTOCK;
                break;

              case 5:
                dataStatus = "";
                break;

              default:
                break;
            }
            dataStatusName = getChoiceName()[arg1];
            CustomerDialog systemDialog = new CustomerDialog(dataStatusName, dataStatus);

            Intent intent = new Intent();
            intent.putExtra(EXTRA_VALUE, systemDialog);
            if (getTargetFragment() == null) return;
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK,
                intent);
            arg0.dismiss();
          }
        }).create();
  }

  private String[] getChoiceName() {
    for (int i = 0; i < choiceIds.length; i++) {

      choiceStrings[i] = getResources().getString(choiceIds[i]);
    }

    return choiceStrings;
  }
}
